package com.gdal.utils.exception;

import java.util.HashMap;

/**
 * GdalExceptionErrorCode lists the Gdal error codes that correspond
 * to a each exception thrown by the Gdal API.
 */

public class GdalExceptionErrorCode {

    protected static final HashMap<String, Integer> ExceptionErrorCodeMap;

    static {
        try {
            ExceptionErrorCodeMap = new HashMap<String, Integer>();
            ExceptionErrorCodeMap.put("com.gdal.utils.exception.GdalRuntimeException", 1001);
            ExceptionErrorCodeMap.put("com.gdal.utils.exception.ExecutionException", 1002);
            ExceptionErrorCodeMap.put("com.gdal.exception.CloudException", 1003);
  
        } catch (Exception e) {
            e.printStackTrace();
            throw new ExceptionInInitializerError(e);
        }
    }

    public static HashMap<String, Integer> getErrCodeList() {
        return ExceptionErrorCodeMap;
    }

    public static int getGdalErrCode(String exceptionName) {
        if (ExceptionErrorCodeMap.containsKey(exceptionName)) {
            return ExceptionErrorCodeMap.get(exceptionName);
        } else {
            s_logger.info("Could not find exception: " + exceptionName + " in error code list for exceptions");
            return -1;
        }
    }

    public static String getCurMethodName() {
        StackTraceElement stackTraceCalls[] = (new Throwable()).getStackTrace();
        return stackTraceCalls[1].toString();
    }
}
